﻿using System;
using System.ComponentModel.Design;

using Action = Microsoft.WowAddonStudio.FrameXml.Components.Actions.Action;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Designers
{
    public class FrameXmlDesignerActionItem : DesignerActionMethodItem
    {
        private readonly Action action;

        /// <summary>
        /// Initializes a new instance of the <see cref="FrameXmlDesignerActionItem"/> class.
        /// </summary>
        /// <param name="actionList">The owner action list.</param>
        /// <param name="action">The action.</param>
        /// <param name="includeAsDesignerVerb">A value indicating whether the action should be included as a designer verb.</param>
        public FrameXmlDesignerActionItem(DesignerActionList actionList, Action action, bool includeAsDesignerVerb)
            : base(actionList, null, action.DisplayName, action.Category, action.Description, includeAsDesignerVerb)
        {
            if (action == null)
                throw new ArgumentNullException("action");

            this.action = action;
        }

        /// <summary>
        /// Raised when the action is invoked.
        /// </summary>
        public event EventHandler Invoked;

        /// <summary>
        /// Gets the action the action item invokes.
        /// </summary>
        public Action Action
        {
            get { return action; }
        }

        /// <summary>
        /// Invokes the action.
        /// </summary>
        public override void Invoke()
        {
            action.Invoke();
            OnInvoked();
        }

        /// <summary>
        /// Raises the <see cref="Invoked" /> event.
        /// </summary>
        protected virtual void OnInvoked()
        {
            if (Invoked != null)
                Invoked(this, EventArgs.Empty);
        }

    }
}
